package cn.galudisu.reactivemanifesto.event

import akka.actor.ActorSystem
import akka.event.{ActorEventBus, SubchannelClassification}
import akka.util.Subclassification

class MessageSubclassification extends Subclassification[CircuitBreakerBus#Classifier] {
  override def isEqual(x: CircuitBreakerBus#Classifier, y: CircuitBreakerBus#Classifier): Boolean = x == y
  override def isSubclass(x: CircuitBreakerBus#Classifier, y: CircuitBreakerBus#Classifier): Boolean = y.isAssignableFrom(x)
}

class CircuitBreakerBus(actorSystem: ActorSystem) extends ActorEventBus with SubchannelClassification {
  override type Event = Panel
  override type Classifier = Class[_ <: Panel]

  override protected implicit def subclassification: Subclassification[Classifier] = new MessageSubclassification

  // 分类器
  override protected def classify(event: Panel): Classifier = event.getClass

  override protected def publish(event: Panel, subscriber: Subscriber): Unit =
    subscriber ! event
}